package com.alk.frijava.sample;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;

import com.alk.frijava.candlestickchart.*;

public class CandleStickChartSample extends Application {

    // DAY, OPEN, CLOSE, HIGH, LOW
    private static double[][] data = new double[][]{
            {1,  25, 20, 32, 16},
            {2,  26, 30, 33, 22},
            {3,  30, 38, 40, 20},
            {4,  24, 30, 34, 22},
            {5,  26, 36, 40, 24},
            {6,  28, 38, 45, 25},
            {7,  36, 30, 44, 28},
            {8,  30, 18, 36, 16},
            {9,  40, 50, 52, 36},
            {10, 30, 34, 38, 28},
            {11, 24, 12, 30, 8},
            {12, 28, 40, 46, 25},
            {13, 28, 18, 36, 14},
            {14, 38, 30, 40, 26},
            {15, 28, 33, 40, 28},
            {16, 25, 10, 32, 6},
            {17, 26, 30, 42, 18},
            {18, 20, 18, 30, 10},
            {19, 20, 10, 30, 5},
            {20, 26, 16, 32, 10},
            {21, 38, 40, 44, 32},
            {22, 26, 40, 41, 12},
            {23, 30, 18, 34, 10},
            {24, 12, 23, 26, 12},
            {25, 30, 40, 45, 16},
            {26, 25, 35, 38, 20},
            {27, 24, 12, 30, 8},
            {28, 43, 44, 46, 15},
            {29, 28, 18, 30, 12},
            {30, 29, 17, 31, 11},
            {31, 27, 17, 29, 13}
    };

    @Override 
    public void start(Stage stage) throws Exception {
    	
    	stage.setTitle("Custon Candle Stick Chart Sample");
        //defining the axes
    	
    	final NumberAxis xAxis = new NumberAxis(0,32,1);
        xAxis.setMinorTickCount(1);
        final NumberAxis yAxis = new NumberAxis();
        xAxis.setLabel("Day");
        yAxis.setLabel("Price");
        
        //creating the chart
        final CandleStickChart csc = new CandleStickChart(xAxis,yAxis);
        csc.setTitle("Stock Monitoring, 2014");
        
        //defining a series
        XYChart.Series<Number,Number> series = new XYChart.Series<Number,Number>();
        series.setName("My portfolio");
        //populating the series with data
        for (int i=0; i< data.length; i++) {
            double[] day = data[i];
            series.getData().add(
                new XYChart.Data<Number,Number>(day[0],day[1],new CandleStickValues(day[1],day[2],day[3],day[4]))
            );
        }

        ObservableList<XYChart.Series<Number,Number>> data = csc.getData();
        if (data == null) {
            data = FXCollections.observableArrayList(series);
            csc.setData(data);
            System.out.println("FXC");
        } else {
        	csc.getData().add(series);
        }
       
        Scene scene  = new Scene(csc,800,600);
        stage.setScene(scene);
        stage.show();
    }
    
    public static void main(String[] args) { 
    	launch(args); 
    }
}
